package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.cell.tower.AbstractTower;
import model.cell.tower.LaserTower;
import model.cell.tower.LightningTower;
import model.game.MouseCursor;


public class TowerPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	
	private String[] towerImages = {"Green", "Lightning"};
	
	
	public TowerPanel() {
		
		this.setBackground(Color.BLACK);
		this.setPreferredSize(new Dimension(190, 40));
		this.setBorder(BorderFactory.createLineBorder(Color.gray));
		this.setLayout(new GridLayout(1, 4));
		
		_init();
	}


	private void _init() {
		
		for (int i=0; i < towerImages.length; i++) {
			
			JLabel towerIcon = new JLabel(new ImageIcon(getClass().getResource("/tower"+towerImages[i]+".png")));
			towerIcon.setName(towerImages[i]);
			towerIcon.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
					
					JLabel label = (JLabel) e.getSource();
					
					MouseCursor.setTower(getTowerByName(label.getName()));
				}
				public void mousePressed(MouseEvent e) {}
				public void mouseExited(MouseEvent e) {}
				public void mouseEntered(MouseEvent e) {}
				public void mouseClicked(MouseEvent e) {}
			});
			this.add(towerIcon);
		}
	}
	
	
	public AbstractTower getTowerByName(String name) {
		
		if (name == "Green") return new LaserTower(new Point(), new Dimension(), null);
		if (name == "Lightning") return new LightningTower(new Point(), new Dimension(), null);
		
		return null;
	}
	
}
